#include <bits/stdc++.h>
using namespace std;
set<int>s;
map<int, int>mp;
int a[200005], T, n;
long long ans;
bool b[200005];
int read(){
	char c = getchar();
	while(c != '-' && !isdigit(c)) c = getchar();
	int ch = 1;
	if(c == '-'){
		ch = -1;
		c = getchar();
	}
	int h = 0;
	while(isdigit(c)){
		h = h * 10 + (int)(c - 48);
		c = getchar();
	}
	h *= ch;
	return h;
}
void dfs(int dep){
	if(dep > n){
		long long s = 0;
		for(int i = 2;i <= n;++i)
			for(int j = i - 1;j >= 1;--j)
				if(b[i] == b[j] && a[i] == a[j]) s += a[i];
		ans = max(ans, s);
		return;
	}
	dfs(dep + 1);
	b[dep] = true;
	dfs(dep + 1);
	b[dep] = false;
}
void work(){
	n = read();
	for(int i = 1;i <= n;++i){
		a[i] = read();
		s.insert(a[i]);
		++mp[a[i]];
	}
	int nn = s.size();
	if(nn == n){
		cout << "0\n";
		return;
	}
	if(n <= 20){
		ans = 0;
		memset(b, 0, sizeof(0));
		dfs(1);
		cout << ans << '\n';
	}
	else{
		for(int i = 1;i <= n;++i)
			if(mp[a[i]] > 1 && !b[i]){
				b[i] = true;
				mp[a[i]] -= 2;
				for(int j = i + 1;j <= n;++j)
					if(a[i] == a[j] && !b[j]){
						b[j] = true;
						i = j;
						break;
					}
			}
		long long s = 0;
		for(int i = 2;i <= n;++i)
			for(int j = i - 1;j >= 1;--j)
				if(b[i] == b[j] && a[i] == a[j]) s += a[i];
		cout << s << '\n';
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	T = read();
	for(int i = 1;i <= T;++i)
		work();
	return 0;
}
